#include <iostream>
#include <string>
using namespace std;

int stack[100005], idx = 0;

int main()
{
    int m; cin >> m;
    while(m--)
    {
        string s; cin >> s;
        if(s == "push") 
        {
            int x; cin >> x;
            stack[idx++] = x;
        }
        else if(s == "pop")
        {
            idx--;
        }
        else if(s == "empty")
        {
            if(idx) cout << "NO\n";
            else cout << "YES\n";
        }
        else
        {
            cout << stack[idx - 1] << endl;
        }
    }
    return 0;
}